//
//  LYPictureBrowseTransitionParameter.m
//  LYCustomTransitionDemo
//
//  Created by liyang on 2017/12/5.
//  Copyright © 2017年 liyang. All rights reserved.
//

#import "LYPictureBrowseTransitionParameter.h"

@implementation LYPictureBrowseTransitionParameter

- (void)setTransitionImage:(UIImage *)transitionImage {
    _transitionImage = transitionImage;
    if (transitionImage == nil) {
      _secondVCImgFrame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
    }else{
      _secondVCImgFrame = [self backScreenImageViewRectWithImage:transitionImage];
    }
}

- (void)setTransitionImgIndex:(NSInteger)transitionImgIndex {
    _transitionImgIndex = transitionImgIndex;
    if (transitionImgIndex >= _firstVCImgFrames.count) {
        return;
    }
    _firstVCImgFrame = [_firstVCImgFrames[transitionImgIndex] CGRectValue];
}

//返回imageView在window上全屏显示时的frame
- (CGRect)backScreenImageViewRectWithImage:(UIImage *)image {
    CGFloat imgW = image.size.width  > 0 ? image.size.width  : 0.0;
    CGFloat imgH = image.size.height > 0 ? image.size.height : 0.0;

    CGSize size = CGSizeMake(imgW, imgH);
    CGSize newSize;
    newSize.width = SCREENWIDTH;
    newSize.height = newSize.width / size.width * size.height;
    if (imgW <= 0 || imgH <= 0) {
        newSize.height = 0;
    }
    if (newSize.height > SCREEN_HEIGHT) {
        newSize.height = SCREEN_HEIGHT;
        newSize.width =  size.width * newSize.height / size.height;
    }
    double imageY = (SCREENHEIGHT - newSize.height) * 0.5;
    
    if (imageY < 0) {
        imageY = 0;
    }
    
    CGRect rect =  CGRectMake((SCREEN_WIDTH - newSize.width)/2, imageY > 0 ? imageY : 0, newSize.width, newSize.height > 0 ? newSize.height : 0);
    
    return rect;
}

@end
